function getDate() {
    let date = new Date();
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate()
    let hour = date.getHours()
    let minute = date.getMinutes()
    let second = date.getSeconds()
    month = month < 10 ? '0' + month : month
    day = day < 10 ? '0' + day : day
    hour = hour < 10 ? '0' + hour : hour
    minute = minute < 10 ? '0' + minute : minute
    second = second < 10 ? '0' + second : second
    return [year, month, day, hour, minute, second];
}
function getStartDate(isReduce) {
    var date = getDate();
    var year = date[0] - 2;
    var month = date[1];
    var day = date[2] - 7;
    if (day < 1) {
        month = month - 1;
        if (month < 1) {
            month = 12;
            day = 31 + day;
        } else {
            day = 30 + day;
        }
    }
    day = day < 10 ? '0' + day : day
    return `${isReduce ? year + 2 : year}-${month}-${day}`;
}

function getEndDate(isReduce) {
    var date = getDate();
    if (isReduce) {
        //如果为true则是减一天，那么要判断是否小于10，因为如果data[2]为07的话，那么减1就变成6了，而不是06
        var day = date[2] - 1;
        day = day < 10 ? '0' + day : day
        date[2] = day;
    }
    return `${date[0]}-${date[1]}-${date[2]}`;
}
//时间转换Wed Oct 18 2023 00:00:00 GMT+0800 (中国标准时间) => 2023-09-18
function timeFormat(time) {
    var date = new Date(time);
    var year = date.getFullYear();
    var month = date.getMonth()+1;
    var day = date.getDate()
    month = month < 10 ? '0' + month : month
    day = day < 10 ? '0' + day : day
    return `${year}-${month}-${day}`;
}
function timeToTimestamp(time) {
    time = time.split('-');
    var year = time[0];
    //将月份中的0去掉
    var month = time[1].indexOf('0') == 0 ? time[1].substring(1) : time[1];
    //将日中的0去掉
    var day = time[2].indexOf('0') == 0 ? time[2].substring(1) : time[2];
    var date = new Date(year, month-1, day).getTime();
    return date;
}
export {
    getDate,
    getStartDate,
    getEndDate,
    timeToTimestamp,
    timeFormat
}